package com.lagou.edu.course.controller;

import com.lagou.edu.common.UserManager;
import com.lagou.edu.common.result.ResponseDTO;
import com.lagou.edu.course.model.response.CourseSectionListResult;
import com.lagou.edu.course.service.SectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程章节Controller
 *
 * @author lm
 * @since 2021/10/29 16:11
 */
@Slf4j
@RestController
@RequestMapping("/course/section")
public class SectionFrontController {
    @Autowired
    SectionService sectionService;

    /**
     * 通过课程Id获取章节和课时
     *
     * @param courseId 课程ID
     * @return
     */
    @GetMapping(value = "/getSectionAndLesson")
    public ResponseDTO<CourseSectionListResult> getSectionAndLesson(@RequestParam("courseId") Integer courseId){
        log.info("通过课程Id获取章节和课时 courseId:{}",courseId);
        Integer userId = UserManager.getUserId();
        return ResponseDTO.success(sectionService.getSectionInfoByCourseId(userId, courseId));
    }
}
